(function($, doc) {
	$.init({});		
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;
    var phone;
    
window.onload = function(){
	 
	mui.plusReady(function(){
	  	var goods_id=plus.webview.currentWebview().goods_id;
	  	
	  	//从服务器获取数据
	  	$.ajax({
				url: apiurl + "Store/goods_detail/",
				data: {'goods_id':goods_id,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'post',
				timeout: 10000,
				success: function(data) {
					console.log(JSON.stringify(data));
					if(data.status ==-3){
						mui.toast(data.msg);
						app.out();
						return false;
					}
						// 请求成功
					var obj=data.goods_images;
					var len=obj.length;
					var first_slide=obj[0]['image_url'];
					var last_slide=obj[len-1]['image_url'];
					
					var htms='';
					htms+='<div class="mui-slider-group mui-slider-loop">';
					htms+='<div class="mui-slider-item mui-slider-item-duplicate">';
					htms+='<a><img src="'+last_slide+'"></a></div>';
					for(z in obj){
						htms+='<div class="mui-slider-item">';			
						htms+='<a>';
						htms+='<img src="'+obj[z]['image_url']+'">';
						htms+='</a>';
						htms+='</div>';
					}
					htms+='<div class="mui-slider-item mui-slider-item-duplicate">';
					htms+='<a>';
					htms+='<img src="'+first_slide+'">';
					htms+='</a>';
					htms+='</div>';
					htms+='</div>';
					
					htms+='<div class="mui-slider-indicator">';
					htms+='<div class="mui-indicator mui-active"></div>';
					htms+='<div class="mui-indicator"></div>';
					htms+='<div class="mui-indicator"></div>';
					htms+='<div class="mui-indicator"></div>';
					htms+='<div class="mui-indicator"></div>';
				    htms+='</div>';
					document.querySelector('.mui-slider').innerHTML=htms;
                    //获得slider插件对象
					var gallery = mui('.mui-slider');
					gallery.slider({
					  	interval:5000  //自动轮播周期，若为0则不自动播放，默认为0；
					});

					/*
					document.querySelector("#goods_slide_images").innerHTML = template('slide-img-template',
						{'data':obj,'first_slide':first_slide});
					*/
					
					document.getElementById('goods_name').innerHTML=data.good.goods_name;
					document.getElementById('shop_price').innerHTML=data.good.shop_price;
					document.getElementById('store_name').innerHTML=data.store.store_name;
					document.getElementById('store_name').setAttribute('data-id',data.store.store_id);
					document.getElementById('store_name').setAttribute('data-name',data.store.store_name);
					
					var htm='';
					obj=data.goods_detail_images;
					for(z in obj){
						htm+='<img src="'+obj[z]['image_url']+'" style="padding-left:5px;padding-right:5px;width:100%;">';
					}
					htm+='<p style="padding-left:5px;padding-right:5px;">'+data.good.goods_remark+'</p>';
					document.getElementById('goods_detail').innerHTML=htm;
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
		});
	  	
		//关闭等待框
		plus.nativeUI.closeWaiting();
		//显示当前页面
		mui.currentWebview.show();
	});
}


	doc.getElementById('show_good_detail').addEventListener('tap', function() {
		if(doc.getElementById('slider_down').style.display=="block"){
			doc.getElementById('goods_detail').style.display="block";
			doc.getElementById('slider_down').style.display="none";
			doc.getElementById('slider_up').style.display="block";
		}
		else{
			doc.getElementById('goods_detail').style.display="none";
			doc.getElementById('slider_down').style.display="block";
			doc.getElementById('slider_up').style.display="none";
		}
	})
	
	/*
	doc.getElementById('slider_down').addEventListener('tap', function() {
		doc.getElementById('goods_detail').style.display="block";
		doc.getElementById('slider_down').style.display="none";
		doc.getElementById('slider_up').style.display="block";
	})
	
	doc.getElementById('slider_up').addEventListener('tap', function() {
		doc.getElementById('goods_detail').style.display="none";
		doc.getElementById('slider_down').style.display="block";
		doc.getElementById('slider_up').style.display="none";
	})*/

	
}(mui, document));